home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
cvt100.zip
/
KEYIO.C
< prev
next >
Wrap
Text File
|
1988-08-01
|
15KB
|
395 lines
#include <stdio.h>
#include <dos.h>
#include <bios.h>
#define ESC 0x1B /* ASCII ESCape character */
#define ESCAPE 0x11B /* Keyboard ESCape scan code */
#define DEL 0x7F /* ASCII DELete character */
#define BKSP 0xE08 /* Keyboard BacKSPace scan code */
#define F1 0x3B00 /* Keyboard Function key 1 scan code */
#define F2 0x3C00 /* Keyboard Function key 2 scan code */
#define F3 0x3D00 /* Keyboard Function key 3 scan code */
#define F4 0x3E00 /* Keyboard Function key 4 scan code */
#define F5 0x3F00 /* Keyboard Function key 5 scan code */
#define F6 0x4000 /* Keyboard Function key 6 scan code */
#define F7 0x4100 /* Keyboard Function key 7 scan code */
#define F8 0x4200 /* Keyboard Function key 8 scan code */
#define F9 0x4300 /* Keyboard Function key 9 scan code */
#define F10 0x4400 /* Keyboard Function key 10 scan code */
#define UP 0x4800 /* Keyboard Up Arrow scan code */
#define DOWN 0x5000 /* Keyboard Down Arrow scan code */
#define LEFT 0x4B00 /* Keyboard Left Arrow scan code */
#define RIGHT 0x4D00 /* Keyboard Right Arrow scan code */
#define K7 0x4737 /* Keyboard Numeric 7 scan code */
#define K8 0x4838 /* Keyboard Numeric 8 scan code */
#define K9 0x4939 /* Keyboard Numeric 9 scan code */
#define KDASH 0x372A /* Keyboard Numeric Asteric scan code */
#define K4 0x4B34 /* Keyboard Numeric 4 scan code */
#define K5 0x4C35 /* Keyboard Numeric 5 scan code */
#define K6 0x4D36 /* Keyboard Numeric 6 scan code */
#define KCOMA 0x4A2D /* Keyboard Numeric Dash(minus) scan code */
#define K1 0x4F31 /* Keyboard Numeric 1 scan code */
#define K2 0x5032 /* Keyboard Numeric 2 scan code */
#define K3 0x5133 /* Keyboard Numeric 3 scan code */
#define KENTR 0x4E2B /* Keyboard Numeric + (plus) scan code */
#define K0 0x5230 /* Keyboard Numeric 0 scan code */
#define KDOT 0x532E /* Keyboard Numeric Period scan code */
/*****************************************************************************/
/* function prototypes */
void Keyinit( void ); /* Initialize the keyboard system */
int ConChk( void ); /* Check the keyboard for keystrokes */
unsigned int GetKey( void ); /* Retrieve a scan code from keyboard */
int DoKey( void ); /* Transmit a key sequence */
static void TransKey( unsigned ); /* Translate a keystroke to a sequence */
static int TransNumKey(unsigned); /* Translate Numeric Keypad keystroke */
static int TransApplKey(unsigned);/* Translate Application Keypad keystroke */
static void SendBksp( void ); /* Transmit the backspace character */
void SetKeyPad( int ); /* Set the keypad to APPLICATION, NUMERIC */
void SetCursorKey( int ); /* Set the cursor key mode */
/*****************************************************************************/
/* Global variables */
unsigned char backspace; /* Backspace/Delete translation flag */
unsigned char keyclick; /* Keyclick mode on/off */
unsigned char applkeypad; /* Current state of keypad */
void TTSetup( void ); /* Communications setup function */
void VidSetup( void ); /* Video setup function */
void KeySetup( void ); /* Keyboard setup function */
void VTSetup( void ); /* VT emulation setup function */
void FileSetup( void ); /* File system setup function */
/*****************************************************************************/
/* External variables */
/*****************************************************************************/
/* Local Static data */
static char cursorkey = '['; /* Sequence character in cursor key */
static union REGS regs; /* Registers for int86 call */
/*****************************************************************************/
/*****************************************************************************/
/* K E Y I N I T -- Initialize the keyboard system */
void Keyinit() {
delay(1); /* Initialize Turbo C delay function */
if (GetKeySetup() == 0) { /* If no values were available from */
backspace = 0; /* a setup file then provide defaults */
keyclick = 0;
applkeypad = 0;
}
}
/* C O N C H K -- Check if any key strokes are waiting, check hot keys */
ConChk()
{
void (*setupfunct)(); /* Pointer to selected setup function */
regs.h.ah = 0x1; /* Use function 1 of interrupt 0x16 */
int86(0x16,®s,®s); /* to check for waiting keystrokes */
if ( regs.x.flags & 0x40 ) /* If the zero flag is set then no keys */
return(0);
else { /* Else a key has been pressed */
switch (regs.x.ax) { /* Check to see if it was a hot key */
case F5:
setupfunct = TTSetup;
break;
case F6:
setupfunct = VidSetup;
break;
case F7:
setupfunct = KeySetup;
break;
case F8:
setupfunct = VTSetup;
break;
case F9:
setupfunct = FileSetup;
break;
default: /* If not a Setup key return 1 indicating */
return(1); /* a keystroke is ready */
}
GetKey(); /* Retrieve keystroke */
(*setupfunct)(); /* Call the selected setup function */
return(0); /* Return indicating no keystroke here yet */
}
}
/* G E T K E Y -- Return a keyboard scan code */
unsigned int GetKey() {
register unsigned int scancode;
scancode = bioskey(0); /* Get a keystroke, waits if none ready */
if (keyclick) { /* If keyclick flag is set */
sound(250); /* Turn on low frequency sound */
delay(5); /* Wait a short time period */
nosound(); /* Turn off the sound */
}
return(scancode); /* Return the retrieved scancode */
}
/* D O K E Y -- Retrieve and interpret a keystroke */
DoKey() {
unsigned scancode;
scancode = GetKey(); /* Get a keystroke, waits if none ready */
if (scancode == F10) /* Check for EXIT character */
return(-1);
else /* Else translate the pressed key */
TransKey(scancode);
return(0); /* return success */
}
/* T R A N S K E Y -- translate a scancode into a keystroke sequence */
static void TransKey( unsigned key ) {
switch(key) { /* Evaluate this keyboard scan code */
case BKSP: /* Backspace pressed */
SendBksp();
break;
case F1: /* Function key 1 pressed */
ttoc( ESC );
ttoc( 'P' );
break;
case F2: /* Function key 2 pressed */
ttoc( ESC );
ttoc( 'Q' );
break;
case F3: /* Function key 3 pressed */
ttoc( ESC );
ttoc( 'R' );
break;
case F4: /* Function key 4 pressed */
ttoc( ESC );
ttoc( 'S' );
break;
case UP: /* Up Arrow